﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Expo.Training.DataAccess.Portal.News;
using Expo.Training.Entity;
using System.Data;

public partial class Controls_NewListControl : ControlPageBase
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        BindNewList();
    }

    private void BindNewList()
    {
        //获取慈溪图片新闻
        //News objNews = new News();
        //objNews.Type = 22;
        //objNews.Status = 1;
        //objNews.IsPass = 1;
        //objNews.CustomerID = this.Customer.CustomerID;
        //objNews.ReturnCount = 5;
        //objNews.OrderBy = "AddTime DESC";
        //DataTable objDT = objNews.QueryDataTable();
        //objNews.Dispose();
        //rptPicNews.DataSource = objDT;
        rptPicNews.DataSource = NewsModule.GetNewsListByType(this.Customer.CustomerID, 103, 5);
        rptPicNews.DataBind();

        //巴马社区快讯
        this.rptNews_List.DataSource = NewsModule.GetNewsListByType(this.Customer.CustomerID, 101, 8);
        this.rptNews_List.DataBind();

        //巴马最新公告
        DataTable dt = NewsModule.GetNewsListByType(this.Customer.CustomerID, 102, 8);
        this.rpt_NewList_nv1.DataSource = dt;
        this.rpt_NewList_nv1.DataBind();

        //慈溪专题
        dt = NewsModule.GetNewsListByType(this.Customer.CustomerID, 33, 8);
        rpt_NewsList_n.DataSource = dt;
        this.rpt_NewsList_n.DataBind();
    }


    private DataTable SelectTop(int top, DataTable dt)
    {
        if (dt.Rows.Count < top) return dt;

        DataTable newTable = dt.Clone();
        //选取所有行
        DataRow[] rows = dt.Select("1=1");
        for (int i = 0; i < top; i++)
        {
           
            newTable.ImportRow(dt.Rows[i]); 
        }
        dt.Dispose();
        return newTable;
    }
}
